/*  Copyright (c) 2004-2007 Srichand Pendyala
 *  sharpscoregui.cs - This file is part of Sharpscore.
 *
 *  Sharpscore is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  Sharpscore is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with Sharpscore; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

using Gtk;
using GtkSharp;
using System;
using Scorethingy;
using System.Timers;

class SharpscoreGui{
	Label l1, l2, l3, l4;
	Fixed f1;
	Window wind;
	Timer timer1;
	public Score sc;
	public SharpscoreGui(){
		try{
			sc = new Score();
		}
		catch (ScoreException se){
			Console.WriteLine("Exception Occured: {0}", se.ToString());
		}
		Application.Init();
		CreateLabels(sc);
		CreateTimer();	
		CreateFixed();
		CreateWindow();
	}
	
	void CreateLabels(Score sc){
		l1 = new Label("Match: "+sc.Match);
		l2 = new Label("Now Playing: "+sc.NowPlaying);
		l3 = new Label("Score: "+sc.FinalScore);
		l4 = new Label("Date: "+sc.date);
	}
	
	void CreateTimer(){
		timer1 = new Timer(60000);
		timer1.Elapsed += new ElapsedEventHandler(ScoreRefresh);
		timer1.Start();
	}
	
	void CreateFixed(){
		f1 = new Fixed();
		f1.Add(l1);
		f1.Add(l2);
		f1.Add(l3);
		f1.Add(l4);
		f1.Move(l2, 0, 20);
		f1.Move(l3, 0, 40);
		f1.Move(l4, 0, 60);
	}
	
	void CreateWindow(){
		wind = new Window("Sharpscore");
		wind.Add(f1);
		wind.DeleteEvent += delete_event;
		wind.AllowGrow = false;
		wind.AllowShrink = false;
		wind.ShowAll();
	}
	
	
	public void ScoreRefresh(System.Object src, ElapsedEventArgs ee){
		sc.GetScore();
		l1.Text = "Match: "+sc.Match;
		l2.Text = "Now Playing: "+sc.NowPlaying;
		l3.Text = "Score: "+sc.FinalScore;
		l4.Text = "Date: "+sc.date;
	}
	public void Run(){
		Application.Run();
	}

	public static void delete_event(object obj, DeleteEventArgs args){
		Application.Quit();
	}
}
		

class mainclass{
	public static void Main(string[] args){
		SharpscoreGui ssg = new SharpscoreGui();
		ssg.Run();
	}
}
